package com.te;

import android.graphics.Canvas;
import android.util.Log;
import android.view.SurfaceHolder;

public class ViewThread extends Thread {
    private GameWorld gameWorld;
    private SurfaceHolder surfaceHolder;
    private boolean       mRun = false;

    public ViewThread(GameWorld gameWorld) {
        this.gameWorld = gameWorld;
        surfaceHolder = gameWorld.getHolder();
    }

    public void setRunning(boolean run) {
        mRun = run;
    }

    @Override
    public void run() {
        Canvas canvas = null;
        Log.d("Thread", "Thread in run");
        long startTime = System.currentTimeMillis();
        long nbrOfRuns = 0;
        long elapsedTime, nbrOfSeconds;
        String fPS = "";


        while (mRun) {
            canvas = surfaceHolder.lockCanvas();
            if (canvas != null) {
                // Log.d("Thread","Thread in while");
                gameWorld.updateWorld();
                gameWorld.doDraw(fPS, canvas);
                //elapsedTime = System.currentTimeMillis() - startTime;
                //nbrOfSeconds = elapsedTime / 1000;
                //fPS = " " + (int) (nbrOfRuns / (nbrOfSeconds + 0.00001));
                //nbrOfRuns++;
                surfaceHolder.unlockCanvasAndPost(canvas);
                
            }
        }
    }
}